package hp.com.servlet.ProductServlet;

import hp.com.service.ProductService;
import hp.com.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;

@WebServlet("/CheckSukPrice")
public class CheckSukPriceServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductService pds = new ProductServiceImpl();
        String suk = req.getParameter("suk");
        suk=suk.replace(",","|");
        try{
            double d = pds.GetSukPrice(suk);
            //将价格的小数点后保留到两位（针对整数价格只显示一位小数）
            DecimalFormat df = new DecimalFormat("#.00");
            String ret = df.format(d);
            resp.getWriter().print(ret);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
